/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "MapChunk.h"
#include "TerrainManager.h"

namespace PQGame
{
	MapChunk::MapChunk(int index,AdtFile* file,int col,int row)
		: _file(file),_index(index),_col(col),_row(row)
	{
		//id=_row*3*16*16+_col*16*16+_index;

		_header=file->getChunkHeader(_index);

		_areaId=_header->areaid;
		_xbase=_header->xpos;
		_ybase=_header->ypos;
		_zbase=_header->zpos;

		//convert coordinate to world
		_zbase = _zbase*-1.0f + ZERO_POINT;
		_xbase = _xbase*-1.0f + ZERO_POINT;

		//initVerticesPosition();
		//initVerticesNormal();
		//initTextureLayers();
		initTerrainChunk();

	}

	void MapChunk::initTerrainChunk()
	{
		float *heights=_file->getChunkVerticesHeight(_index);
		
		int index=0;
		int ptr=0;
		
		for (int j=0; j<17; j++) {
			if((j%2)){//odd
				ptr+=8;
			}else{
				for (int i=0; i<9; i++) {
					_heights[index]=_ybase+heights[ptr];
					index++;
					ptr++;
				}
			}
			
		}

	}


}
